﻿using System;
using System.Reflection;
using System.Windows;

namespace Wpf
{
    internal class Program
    {
        [STAThread]
        private static void Main(string[] args)
        {
            Application app = new Application();
            //app.ShutdownMode = ShutdownMode.OnMainWindowClose;
            app.DispatcherUnhandledException += App_DispatcherUnhandledException;
            app.Activated += App_Activated;
            app.Deactivated += App_Deactivated;
            app.Exit += App_Exit;
            app.Startup += App_Startup;
            var str = 1;
            switch (str)
            {
                case 1:
                    app.Run(new Windows.MainWindow());
                    //app.Run(new Windows.ControlsWindow());
                    break;

                case 2:
                    var main = new Windows.MainWindow();
                    app.MainWindow = main;
                    main.Show();
                    app.Run();
                    break;

                case 3:
                    app.StartupUri = new Uri("Windows/MainWindow.xaml", UriKind.Relative);
                    app.Run();
                    break;

                default:
                    app.Run(new Windows.MainWindow());
                    break;
            }
        }

        private static void App_Startup(object sender, StartupEventArgs e)
        {
            System.Diagnostics.Trace.WriteLine(MethodInfo.GetCurrentMethod().Name);
        }

        private static void App_Exit(object sender, ExitEventArgs e)
        {
            System.Diagnostics.Trace.WriteLine(MethodInfo.GetCurrentMethod().Name);
        }

        private static void App_Deactivated(object sender, EventArgs e)
        {
            System.Diagnostics.Trace.WriteLine(MethodInfo.GetCurrentMethod().Name);
        }

        private static void App_Activated(object sender, EventArgs e)
        {
            System.Diagnostics.Trace.WriteLine(MethodInfo.GetCurrentMethod().Name);
        }

        private static void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            System.Diagnostics.Trace.WriteLine(MethodInfo.GetCurrentMethod().Name);
        }
    }
}

/*
 * WPF 基础
 * 应用程序管理
 * 1.创建WPF应用程序
 * 两种方式：
 * a.App.xaml中定义
 *  StartupUri="MainWindow.xaml"
 * b.自定义类自定义Main方法
 *
 * 2.应用程序退出
 *  ShutdownMode:OnLastWindowClose(默认)，OnExplicitShutdown,OnMainWindowClose
 * a. App.xaml 中定义
 *  ShutdownMode="OnExplicitShutdown"
 * b. 自定义类中 必须在Run方法前调用
 *
 * 3.定义事件
 * xaml 后台代码
 *
 * 4.wpf应用程序的生命周期
 *
 * 5.窗体
 * 由xaml和后台代码组成，或者将后台代码放到xaml中
 * <x:code>
 * <![CDATA[
 * //TODO:your C# code
 * ]]>
 * </x:code>
 *
 * 6.窗体的生命周期
 *  a.SourceInitiated=>b.Actived=>c.Loaded=>d.ContentRender=>e.Deactived=>f.Closed
 *
 * 7.其他窗体属性-常用
 *  a.WindowStyle - 窗体边框模式,ResizeMode,WindowStartupLocation,WindowState
 *  b.Title,TopMost,ShowInTaskbar
 *
 * 8.容器控件
 * StackPanel：堆叠方式显式控件
 * WrapPanel:以流的方式显式控件，从左到右从上到下
 * DockPanel:基本结构布局方式设置布局
 *

     */